<style>
fieldset{
	width: 70%;
	padding:10px;	
	margin-bottom: 5px;
}
fieldset legend{
	color: #4C4C4C;
	display: block;
	font-style: italic;
	font-weight: 600;
	height: 20px;
}
fieldset ul li{
	height: 25px;	
	line-heigt: 20px;	
}
fieldset ul li input{
	float:left;
	margin-top: 2px;
	margin-right: 5px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
	$("#frmAEManufacturer").submit(function(){
		var msg = "";
		if($("#name").attr("value") == ""){
			msg +="Thiếu tên nhà sản xuất.\n";
		}
		if($("#man_logo").attr("value") == ""){
			msg +="Chưa chọn logo.";
		}
		if(msg != ""){
			alert(msg);
			return false;
		}
	});
	//xóa
	$("#btnDelete").click(function(){
		var valid= false;
		var arrChkId = $(".chkId");
		var strIDs = "";
		for(var i =0; i < arrChkId.length; i++){
			if(arrChkId.eq(i).attr("checked")){
				valid = true;
				if(strIDs!=""){
					strIDs +=","+ arrChkId.eq(i).attr("value");
				}else{
					strIDs +=arrChkId.eq(i).attr("value");
				}
				//break;
			}
		}
		if(valid){
			if(confirm("Bạn thực sự muốn xóa những Hãng sản xuất này?")){
				$("#hddIDs").attr("value", strIDs);
				$("#frmActions").attr("action", "<?php echo $this->url(array(), 'admin_manufacturer_delete');?>");
			}else{
				return false;
			}
		}else{
			alert("Xin hãy chọn hãng sản xuất muốn xóa!");
			return false;
		}
	});
});
function BrowseServer()
{

	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;
	finder.basePath = '<?php echo PUBLIC_PATH."/ckfinder/";?>' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	
	finder.selectActionFunction = function(fileUrl){
		
		document.getElementById( "man_logo" ).value = fileUrl ;
		
	}
	finder.popup() ;

	
}
</script>
<div id="r-heading">
	<img src="<?php echo PUBLIC_URL.'/admin/images/category.png';?>" alt=""/>
	<span>Danh sách hãng sản xuất</span>
</div>
<?php
//nếu có message thì hiển thị
if(!empty($this->message)){
	echo '<div id="message">'.$this->message.'</div>';
} 
?>
<div style="width:40%; float:left;">
	<form id="frmAEManufacturer" method = "post" action="">
		<div class = "row">
			<label for="name">Tên hãng sản xuất:</label>
			<?php if(isset($this->man)){?>
			<input  type="text" name="name" id="name" size= "50" value="<?php echo $this->man->name;?>"/>
			<?php }else{?>
			<input type="text" name="name" id="name" size= "50"/>
			<?php }?>
		</div>
		<div class = "row">
			<label for="logo">Logo hãng sản xuất:</label>
			<?php if(isset($this->man)){?>
			<input type="text" name="logo" id="man_logo" size= "50" value="<?php echo $this->man->logo;?>"/>
			<?php }else{?>
			<input type="text" name="logo" id="man_logo" size= "50"/>
			<?php }?>
			<input type="button" class="button" value = "Chọn Ảnh" onclick="BrowseServer();"/>
		</div>
		<div class ="row">
			<label for = "priority">Mức ưu tiên:</label>
			<?php if(isset($this->man)){?>
			<input type="text" name="priority" id="priority" size= "50" value="<?php echo $this->man->priority;?>"/>
			<?php }else{?>
			<input type="text" name="priority" id="priority" size= "50"/>
			<?php }?>
		</div>
		<div class="row">
			<label for="page_title">Tiêu đề trang (thẻ title)</label>
			<?php if(isset($this->man)){?>
			<input style="width: 350px;" type="text" name="page_title" id="page_title" size="30" value="<?php echo $this->man->page_title;?>"/>
			<?php }else{?>
			<input style="width: 350px;" type="text" name="page_title" id="page_title" size="30"/>
			<?php }?>
		</div>
		<div class="row">
			<label for="page_description">Mô tả trang (thẻ description)</label>
			<?php if(isset($this->man)){?>
			<textarea style="width: 350px; height:100px;" name="page_description" id="page_description"><?php echo $this->man->page_description;?></textarea>
			<?php }else{?>
			<textarea style="width: 350px; height:100px;" name="page_description" id="page_description"></textarea>
			<?php }?>
		</div>
		<div class="row">
			<label for="tag">Tag (thẻ keyword)</label>
			<?php if(isset($this->man)){?>
			<input style="width: 350px;" type="text" name="tag" id="tag" size="30" value="<?php echo $this->man->tag;?>"/>
			<?php }else{?>
			<input style="width: 350px;" type="text" name="tag" id="tag" size="30"/>
			<?php }?>
		</div>
		<fieldset>
			<legend>Chọn thể loại sản phẩm</legend>
			<ul>
				<?php
					foreach($this->arrPCategories as $pCategory){
						echo "<li>";
						if(isset($this->man) && in_array($pCategory->id, Helper_Model::GetColumnsValues('man_cat', 'cat_id', 'man_id ='.$this->man->id))){
							echo "<input checked='checked' type='checkbox' name='category_id[]' value='".$pCategory->id."'/>";
						}else{
							echo "<input type='checkbox' name='category_id[]' value='".$pCategory->id."'/>";
						}
						echo "<label>".$pCategory->name."</label>";
						echo "</li>";
					}
				?>
			</ul>
		</fieldset>
		<div class="row">
			<input id="btnSubmit" type="submit" value="Lưu" class="button"/>
			<input type="reset" value="Làm lại" class="button"/>
		</div>
	</form>
</div>
<div style="width: 60%; float: left;">
	<form id="frmActions" action="" method="post">
		<div id="actions">
			<!-- <input type="text" id="txtKeyword" name="keyword" class="text" value="" size="25"/>
			<input type="submit" id="btnSearch" class="button" value="Tìm kiếm"/>-->
			<input type="button" class="button" value="Thêm mới" onclick="location='<?php echo $this->url(array('id' => ''), 'admin_manufacturer');?>';"/>
			<input type="submit" id="btnDelete" class="button" value="Xóa các mục đã chọn"/>
			<input type="hidden" id="hddIDs" value="" name="ids"/>
		</div>
		<table class="list" cellspacing="0">
			<thead>
				<tr>
					<td width="5%">
						<input type="checkbox" class="chkAll"/>
					</td>
					<td width="45%">
						Tên nhà sản xuất
					</td>
					<td width="25%">
						Logo
					</td>
					<td width="15%">
						Thao tác
					</td>
				</tr>
			</thead>
			<tbody>
				<?php
					$count = count($this->arrManufacturers);
					if($count == 0){
				?>
					<tr>
						<td colspan="4" style="color: #fc0202;">
							Chưa có chuyện mục nào trong cơ sở dữ liệu!
						</td>
					</tr>
				<?php
					}else{
						for($i = 0; $i< $count; $i++){
				?>
					<tr <?php if($i == $count - 1) echo 'class="last"';?>>
						<td>
							<input type="checkbox" class="chkId" value="<?php echo $this->arrManufacturers[$i]->id; ?>"/>
						</td>
						<td>
							<a href="<?php echo  $this->url(array('id' => $this->arrManufacturers[$i]->id), 'admin_manufacturer');?>" title="Sửa thông tin nhà sản xuất">
								<?php
									echo $this->arrManufacturers[$i]->name;
								?>
							</a>
						</td>
						<td>
							<img src="<?php echo $this->arrManufacturers[$i]->logo;?>" alt=""/>
						</td>
						<td>
							<a href="<?= $this->url(array('id' => $this->arrManufacturers[$i]->id), 'admin_manufacturer');?>" title="Sửa thông tin nhà sản xuất">Sửa</a>
							|
							<a href="<?= $this->url(array('id' => $this->arrManufacturers[$i]->id), 'admin_manufacturer_delete');?>" onclick="if(!confirm('Bạn thực sự muốn xóa hãng sản xuât này?')) return false;">Xóa</a>
						</td>
					</tr>
				<?php
						}
					}
				?>
			</tbody>
			<tfoot>
				<tr>
					<td>
						<input type="checkbox" class="chkAll"/>
					</td>
					<td>
						Tên hãng sản xuất
					</td>
					<td>
						Logo
					</td>
					<td>
						Thao tác
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
</div>